/*
 * HashTableMain.cc
 *
 *  Created on: Apr 14, 2013
 *      Author: hxin
 */

#include "HashTable.h"
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <cassert>

using namespace std;

int main(int argc, char * argv[]) {
	if (argc == 5) {
			string refName = argv[1];
			string hashName = argv[2];
			int kmerLength;
			stringstream(string(argv[3])) >> kmerLength;
			string pattern = argv[4];
			HashTable ht(pattern);

			int oneCount = 0;
			for (int i = 0; i < pattern.size(); i++)
				if (pattern[i] == '1')
					oneCount++;

			cout << "oneCount" << oneCount << endl;
			assert(oneCount == kmerLength);
			cout << "Generate with KmerLength: " << kmerLength << endl;

			ht.generateHash(refName, hashName);
	} else if (argc == 4) {
		string refName = argv[1];
		string hashName = argv[2];
		int kmerLength;
		stringstream(string(argv[3])) >> kmerLength;
		HashTable ht(kmerLength);

		cout << "Generate with KmerLength: " << kmerLength << endl;

		ht.generateHash(refName, hashName);
	} else if (argc == 3) {
		HashTable ht;
		string refName = argv[1];
		string hashName = argv[2];

		cout << "Generate" << endl;

		ht.generateHash(refName, hashName);
	} else if (argc == 2) {
		HashTable ht;
		string hashName = argv[1];
		ht.loadHash(hashName);
		ht.loadChromo(0);
	} else {
		cerr << "Usage:$> ./HashTable refFile hashFile kmerLength pattern" << endl
				<< "Usage:$> ./HashTable refFile hashFile kmerLength" << endl
				<< "Usage:$> ./HashTable refFile hashFile" << endl
				<< "Usage:$> ./HashTable hashFile" << endl;
		exit(1);
	}
	return 0;
}
